package com.test.nnooolwdeaer.view_wooden.info_input_wooden;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import static com.test.nnooolwdeaer.constant_wooden.Constant_wooden.Data_Action_Phone_wooden;

import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.bean_wooden.StaticVariate_wooden;
import com.test.nnooolwdeaer.bean_wooden.process_wooden.ProcessData_wooden;
import com.test.nnooolwdeaer.bean_wooden.process_wooden.ProcessInfo_wooden;
import com.test.nnooolwdeaer.constant_wooden.Constant_wooden;
import com.test.nnooolwdeaer.util_wooden.StringUtil_wooden;
import com.test.nnooolwdeaer.util_wooden.helper_wooden.UserInfoHelper_wooden;
import com.test.nnooolwdeaer.view_wooden.TrackEditText;
import com.test.nnooolwdeaer.view_wooden.base_wooden.BaseInfoInputViewManager_wooden;
import com.test.nnooolwdeaer.view_wooden.base_wooden.OnInputChangeListener_wooden;

public class InputViewManager_wooden extends BaseInfoInputViewManager_wooden {

    private TextView titleTv_wooden;
    private TrackEditText inputEt_wooden;

    private OnInputChangeListener_wooden onInputChangeListener_wooden;

    public InputViewManager_wooden(View view, ProcessData_wooden data,@NonNull String trackWord){
        super(view,data,trackWord);
    }

    @Override
    protected void init_wooden(){

        titleTv_wooden = mView_wooden.findViewById(R.id.view_input_tv_title);
        inputEt_wooden = mView_wooden.findViewById(R.id.view_input_et_input);

        inputEt_wooden.sTrackWord(trackWord);

        setTitle_wooden(mData_wooden.getTitle_wooden());
        inputEt_wooden.setHint(StringUtil_wooden.getSafeString_wooden(mData_wooden.getHint_wooden()));

        //联系人电话输入数字
        if (mData_wooden.getAction_wooden().equalsIgnoreCase(Data_Action_Phone_wooden)) inputEt_wooden.setInputType(InputType.TYPE_CLASS_NUMBER);

        //加纳卡号和卡名填充
        if (StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Ghana_wooden)&& mData_wooden.getParamName_wooden().equalsIgnoreCase("walletMobile")){
            inputEt_wooden.setText(UserInfoHelper_wooden.getInstance_wooden().getMobile_wooden());
        }
        if (StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Ghana_wooden)&& mData_wooden.getParamName_wooden().equalsIgnoreCase("walletUsername")){
            inputEt_wooden.setText(ProcessInfo_wooden.getInstance_wooden().getRecipientName_wooden());
        }

        inputEt_wooden.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}
            @Override
            public void afterTextChanged(Editable s) {
                if (onInputChangeListener_wooden !=null) onInputChangeListener_wooden.onInputChange_wooden(s.toString());
            }
        });
    }


    @Override
    public boolean checkInput_wooden() {
        if (!mData_wooden.isMustInput_wooden()) return true;
        return !TextUtils.isEmpty(inputEt_wooden.getText());
    }

    @Override
    public String getInput_wooden() {
        return StringUtil_wooden.getSafeString_wooden(inputEt_wooden.gText());
    }

    public void addTextChangeListener_wooden(TextWatcher textWatcher){
        inputEt_wooden.addTextChangedListener(textWatcher);
    }

    public void setTitle_wooden(String title){
        if (TextUtils.isEmpty(title)) titleTv_wooden.setVisibility(GONE);
        else {
            titleTv_wooden.setVisibility(VISIBLE);
            titleTv_wooden.setText(title);
        }
    }

    public void setOnInputChangeListener_wooden(OnInputChangeListener_wooden onInputChangeListener_wooden) {
        this.onInputChangeListener_wooden = onInputChangeListener_wooden;
    }
}
